<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Product;
use Illuminate\Support\Facades\Log;

class IndexController extends Controller
{
    //小程序首页所需要的数据
    function index(){
        //查询轮播图商品
        $product_model = new Product();
        $banner = $product_model->get_banner();

        //查询7个顶级栏目
        $cates = Category::where('parent_id',0)->orderBy('sort','desc')->limit(7)->get()->toArray();

        foreach ($cates as &$cate) {
            $subId =  Category::where('parent_id',$cate['id'])->pluck('id')->toArray();

            $cate['twodata'] = $product_model->get_products([], ['category'=>$subId[0]]);
        }

//        查询10个热销商品
        $rx_products = $product_model->get_products(['type' => REXIAO, 'is_banner' => 0], []);
//        //查询10个特价商品
        $tj_products = $product_model->get_products(['type' => TEJIA, 'is_banner' => 0], []);
        //按照分类查询商品：10条


        $data = [
            'banner'    =>  $banner,
            'bgcolor'   =>  "#FF6347",
            'djname'    =>  '',
            'list'      =>  [],
            'logo'      =>  '',
            'notice'    =>  [],
            //抽奖产品
            'plugin'    =>  [],
            'title'     =>  '毗邻',
            'twoList'   =>  $cates,
            'cates'     =>  $cates,
            'tj'        =>  $tj_products,
            'rx'        =>  $rx_products,
            'message'   => "公告：仅限川渝地区下单，每日10点前下单，成都市区当日送达，其他川渝城市次日物流送达！联系客服：13688472106"
        ];
        return $data;
    }
}
